<template>
  <div>
    <h3>会员权益增加</h3>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td align="right">权益名称</td>
          <td>
            <input type="text" v-model="info.RightName" />
          </td>
        </tr>
        <tr>
          <td align="right"></td>
          <td>
            <input
              type="button"
              value="增加"
              class="btn btn-primary"
              @click="ok"
            />
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';
import { useStore } from '@/stores/user';
const a = useStore();

const router = useRouter();
const route = useRoute();
let info: any = reactive({
  RightName: '',
});

onMounted(() => {
  if (a.userInfo.Id) {
  } else {
    router.push('/loginView');
  }
});

const ok = () => {
  //1.判断有效
  if (info.RightName == '') {
    alert('权益名称不能为空');
    return;
  }
  //2.发送网络请求
  axios({
    url: '/api/Members/MemeberRight',
    method: 'post',
    data: info,
  })
    .then((res) => {
      console.log(res);
      if (res.data > 0) {
        alert('添加成功');
        router.push('/memberRightList');
      } else if (res.data == -1) {
        alert('权益名称重复');
        return;
      } else {
        alert('添加失败');
        return;
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
